﻿using Avalonia.Data;
using Avalonia.Data.Converters;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 畜牧业审核程序国产.Models.RagModel.SenderConverter
{
    internal class IntToBoolConverter: IValueConverter
    {
        // 将 int 转换为 bool，用于绑定到 RadioButton 的 IsChecked 属性
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int selectedOption && parameter is string optionString && int.TryParse(optionString, out var option))
            {
                return selectedOption == option; // 如果选中的选项与当前绑定的选项匹配，则返回 true
            }
            return false; // 默认返回 false
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (bool)value ? int.Parse((string)parameter) : 0;
        }
    }
}
